package wyh.mapper;

import org.apache.ibatis.annotations.*;
import wyh.pojo.Appointment;
import wyh.pojo.Appointment2;
import wyh.pojo.Patient;

import java.util.List;

@Mapper
public interface AppointmentMapper {

    // 根据姓名模糊查询信息
//    @Select("SELECT * FROM 6666666 WHERE 666666666666 LIKE CONCAT('%', #{name}, '%')")
//    List<Patient> MappergetByNameLike(String name);


    @Select("SELECT\n" +
            "    a.*,\n" +
            "    COALESCE(p.name, '') AS patient_name,\n" +
            "    COALESCE(e.name, '') AS escort_name\n" +
            "FROM\n" +
            "    appointment a\n" +
            "        LEFT JOIN\n" +
            "    patientinfo p ON a.patientId = p.patientId\n" +
            "        LEFT JOIN\n" +
            "    escortinfo e ON a.escortId = e.escortId;")
    List<Appointment2> getAllAppointments2();

    @Select("SELECT * FROM appointment")
    List<Appointment> getAllAppointments();

    @Select("SELECT * FROM appointment WHERE appointmentId = #{appointmentId}")
    Appointment getAppointmentById(int appointmentId);

    @Insert("INSERT INTO appointment (patientId, escortId, date) VALUES (#{patientId}, #{escortId}, #{date})")
    @Options(useGeneratedKeys = true, keyProperty = "appointmentId")
    int insertAppointment(Appointment appointment);

    @Update("UPDATE appointment SET patientId = #{patientId}, escortId = #{escortId}, date = #{date} WHERE appointmentId = #{appointmentId}")
    int updateAppointment(Appointment appointment);

    @Delete("DELETE FROM appointment WHERE appointmentId = #{appointmentId}")
    int deleteAppointment(int appointmentId);
}